/*
 * @Description: 
 * @Version: 2.0
 * @Autor: ftt
 * @Date: 2022-03-23 16:38:20
 * @LastEditors: TT
 * @LastEditTime: 2023-03-08 22:24:26
 */

import 'package:flutter/material.dart';
import 'package:ttcomment/ttcomment.dart';
import 'hzy_normal_utils.dart';

abstract class NormalState<T extends StatefulWidget> extends State<T>
    with AbstractNetWork, AbstractWidget, AbstractAttribute {
  /// 生命周期
  ///
  ///

  /// 界面初始化完成
  @override
  void initState() {
    initDefaultState();
    super.initState();
  }

  /// 界面构建视图入口
  @override
  Widget build(BuildContext context) {
    Widget widget = Container();
    if (isneedScaffol) {
      widget = createScaffol(
        context: context,
        safeAreatop: safeAreatop,
        safeAreabottm: safeAreabottm,
        pageState: pageState,
        resizeToAvoidBottomInset: resizeToAvoidBottomInset,
        title: title,
        backgroundColor: backgroundColor,
        navbackcolor: navbackcolor,
      );
    } else {
      widget = createBody(context);
    }
    return widget;
  }

  @override
  void dispose() {
    initDefaultDispose();
    super.dispose();
  }

  @override
  Widget createColumWidget(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      child: LayoutBuilder(
        builder: (context, constraints) {
          configlayoutbuiderConstraints(constraints);
          return SizedBox(
              width: configSizeBoxWidth(constraints),
              child: createonlyColumWidget(context));
        },
      ),
    );
  }

  /// getx 真实包裹的colum 方法
  Widget createonlyColumWidget(BuildContext context) {
    return Column(
      children: [
        createHeaderWidget(),
        Expanded(
          child: createBody(context),
        ),
      ],
    );
  }

  /// 网络请求
  ///
  ///

  @override
  void getnetworkdata({int? type, Map<String, dynamic>? info}) async {}

  /// 创建视图
  ///
  ///

  /// 触发方法
  ///
  ///
  @override
  Map<String, dynamic>? configNetWorkParmas() {
    return null;
  }

  /// 界面进入
  void initDefaultState() {}

  /// 界面销毁
  void initDefaultDispose() {}

  /// 通用刷新state
  void configsetState(VoidCallback fn) {
    if (mounted) {
      setState(() {
        fn();
      });
    }
  }

  /// 获取 屏幕 最大尺寸
  configlayoutbuiderConstraints(BoxConstraints constraints) {}

  double? configSizeBoxWidth(BoxConstraints constraints) {
    return HzyNormalUtils.configSizeMaxW(constraints.maxWidth);
  }
}
